package com.shopx.cm.service.impl;


import com.shopx.base.constants.ResultCodeEnum;
import com.shopx.base.exception.ShopxException;
import com.shopx.base.service.ISysSeqService;
import com.shopx.cm.bean.CmSendRemark;
import com.shopx.cm.dao.db1.CmSendRemarkDao;
import com.shopx.cm.model.CmSendRemarkModel;
import com.shopx.cm.service.ICmSendRemarkService;
import com.shopx.cmm.DTO.PageDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * TODO
 *
 * @author lituo
 * @className: CmSendRemark
 * @date 2025-01-15
 */
@Service
@Slf4j
public class CmSendRemarkServiceImpl implements ICmSendRemarkService {

    @Resource
    private CmSendRemarkDao cmSendRemarkDao;

    @Resource
    private ISysSeqService sysSeqService;

    @Override
    public CmSendRemarkModel selectByPrimaryKey(CmSendRemark cmSendRemark) {
        if (cmSendRemark == null) {
            throw new ShopxException(ResultCodeEnum.PAR_NULL);
        }
        return cmSendRemarkDao.selectByPrimaryKey(cmSendRemark);
    }

    @Override
    @Transactional(value = "db1", rollbackFor = Exception.class)
    public int insertSelective(CmSendRemark cmSendRemark) {
        if (cmSendRemark == null) {
            throw new ShopxException(ResultCodeEnum.PAR_NULL);
        }
        String id = sysSeqService.getTabSeq("CmSendRemark", 4, null);
        cmSendRemark.setCsrId(id);
        int result = cmSendRemarkDao.insertSelective(cmSendRemark);
        if (result != 1) {
            throw new ShopxException(ResultCodeEnum.DB_ERROR);
        }
        return result;
    }

    @Override
    @Transactional(value = "db1", rollbackFor = Exception.class)
    public int updateByPrimaryKeySelective(CmSendRemark cmSendRemark) {
        if (cmSendRemark == null) {
            throw new ShopxException(ResultCodeEnum.PAR_NULL);
        }
        int result = cmSendRemarkDao.updateByPrimaryKeySelective(cmSendRemark);
        if (result != 1) {
            throw new ShopxException(ResultCodeEnum.DB_ERROR);
        }
        return result;
    }

    @Override
    @Transactional(value = "db1", rollbackFor = Exception.class)
    public int deleteByPrimaryKey(CmSendRemark cmSendRemark) {
        if (cmSendRemark == null) {
            throw new ShopxException(ResultCodeEnum.PAR_NULL);
        }
        int result = cmSendRemarkDao.deleteByPrimaryKey(cmSendRemark);
        if (result != 1) {
            throw new ShopxException(ResultCodeEnum.DB_ERROR);
        }
        return result;
    }

    @Override
    public int selectCount(CmSendRemarkModel cmSendRemark) {
        return cmSendRemarkDao.selectCount(cmSendRemark);
    }

    @Override
    public List<CmSendRemarkModel> selectList(CmSendRemarkModel cmSendRemark) {
        List<CmSendRemarkModel> list = cmSendRemarkDao.selectList(cmSendRemark);
        return list;
    }

    @Override
    public PageDTO<CmSendRemarkModel> getListPage(CmSendRemarkModel cmSendRemark) {
        if (cmSendRemark == null) {
            throw new ShopxException(ResultCodeEnum.PAR_NULL);
        }
        PageDTO<CmSendRemarkModel> pageDTO = new PageDTO<CmSendRemarkModel>();
        pageDTO.setiTotalDisplayRecords(selectCount(cmSendRemark));
        pageDTO.setData(selectList(cmSendRemark));
        return pageDTO;
    }

}

